{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## pprint - a module for printing complex data structures that are readable to humans!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "sample_data = [\n",
    "    (1, {'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D'}),\n",
    "    (2, {'e': 'E', 'f': 'F', 'g': 'G', 'h': 'H',\n",
    "         'i': 'I', 'j': 'J', 'k': 'K', 'l': 'L'}),\n",
    "    (3, ['m', 'n']),\n",
    "    (4, ['o', 'p', 'q']),\n",
    "    (5, ['r', 's', 't''u', 'v', 'x', 'y', 'z']),\n",
    "    (6, ['1', '2', '3', '4', '5', '6', '7', '8', '9']),\n",
    "    (7, ['!', '@', '#', '$', '%', '^', '&', '*']),\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "PRINT:\n",
      "[(1, {'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D'}), (2, {'e': 'E', 'f': 'F', 'g': 'G', 'h': 'H', 'i': 'I', 'j': 'J', 'k': 'K', 'l': 'L'}), (3, ['m', 'n']), (4, ['o', 'p', 'q']), (5, ['r', 's', 'tu', 'v', 'x', 'y', 'z']), (6, ['1', '2', '3', '4', '5', '6', '7', '8', '9']), (7, ['!', '@', '#', '$', '%', '^', '&', '*'])]\n",
      "\n",
      "PPRINT\n",
      "[(1, {'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D'}),\n",
      " (2,\n",
      "  {'e': 'E',\n",
      "   'f': 'F',\n",
      "   'g': 'G',\n",
      "   'h': 'H',\n",
      "   'i': 'I',\n",
      "   'j': 'J',\n",
      "   'k': 'K',\n",
      "   'l': 'L'}),\n",
      " (3, ['m', 'n']),\n",
      " (4, ['o', 'p', 'q']),\n",
      " (5, ['r', 's', 'tu', 'v', 'x', 'y', 'z']),\n",
      " (6, ['1', '2', '3', '4', '5', '6', '7', '8', '9']),\n",
      " (7, ['!', '@', '#', '$', '%', '^', '&', '*'])]\n"
     ]
    }
   ],
   "source": [
    "import pprint\n",
    "\n",
    "\n",
    "print('PRINT:')\n",
    "print(sample_data)\n",
    "\n",
    "print('\\nPPRINT')\n",
    "pprint.pprint(sample_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Limiting nested outputs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Single depth:\n",
      "[(...), (...), (...), (...), (...), (...), (...)]\n",
      "\n",
      "Double depth:\n",
      "[(1, {...}),\n",
      " (2, {...}),\n",
      " (3, [...]),\n",
      " (4, [...]),\n",
      " (5, [...]),\n",
      " (6, [...]),\n",
      " (7, [...])]\n",
      "\n",
      "Triple depth:\n",
      "[(1, {'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D'}),\n",
      " (2,\n",
      "  {'e': 'E',\n",
      "   'f': 'F',\n",
      "   'g': 'G',\n",
      "   'h': 'H',\n",
      "   'i': 'I',\n",
      "   'j': 'J',\n",
      "   'k': 'K',\n",
      "   'l': 'L'}),\n",
      " (3, ['m', 'n']),\n",
      " (4, ['o', 'p', 'q']),\n",
      " (5, ['r', 's', 'tu', 'v', 'x', 'y', 'z']),\n",
      " (6, ['1', '2', '3', '4', '5', '6', '7', '8', '9']),\n",
      " (7, ['!', '@', '#', '$', '%', '^', '&', '*'])]\n"
     ]
    }
   ],
   "source": [
    "print('Single depth:')\n",
    "pprint.pprint(sample_data, depth=1)\n",
    "print()\n",
    "print('Double depth:')\n",
    "pprint.pprint(sample_data, depth=2)\n",
    "print()\n",
    "print('Triple depth:')\n",
    "pprint.pprint(sample_data, depth=3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Compact flag - fitting more data on each line"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Without using compact flag:\n",
      "[(1, {'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D'}),\n",
      " (2,\n",
      "  {'e': 'E',\n",
      "   'f': 'F',\n",
      "   'g': 'G',\n",
      "   'h': 'H',\n",
      "   'i': 'I',\n",
      "   'j': 'J',\n",
      "   'k': 'K',\n",
      "   'l': 'L'}),\n",
      " (3, ['m', 'n']),\n",
      " (4, ['o', 'p', 'q']),\n",
      " (5, ['r', 's', 'tu', 'v', 'x', 'y', 'z']),\n",
      " (6, ['1', '2', '3', '4', '5', '6', '7', '8', '9']),\n",
      " (7, ['!', '@', '#', '$', '%', '^', '&', '*'])]\n",
      "\n",
      "With using compact flag:\n",
      "[(1, {'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D'}),\n",
      " (2,\n",
      "  {'e': 'E',\n",
      "   'f': 'F',\n",
      "   'g': 'G',\n",
      "   'h': 'H',\n",
      "   'i': 'I',\n",
      "   'j': 'J',\n",
      "   'k': 'K',\n",
      "   'l': 'L'}),\n",
      " (3, ['m', 'n']), (4, ['o', 'p', 'q']),\n",
      " (5, ['r', 's', 'tu', 'v', 'x', 'y', 'z']),\n",
      " (6, ['1', '2', '3', '4', '5', '6', '7', '8', '9']),\n",
      " (7, ['!', '@', '#', '$', '%', '^', '&', '*'])]\n"
     ]
    }
   ],
   "source": [
    "print('Without using compact flag:')\n",
    "pprint.pprint(sample_data, compact=False)\n",
    "print()\n",
    "print('With using compact flag:')\n",
    "pprint.pprint(sample_data, compact=True)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
